﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using KaoQin.BLL;
using KaoQin.Model;
using KaoQin.Common;


namespace KaoQin.WPFApp
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        #region 变量
        private SysUsersInfo _loginUser;
        #endregion

        

        #region 属性

        public SysUsersInfo LoginUser
        {
            get { return _loginUser; }
            set { _loginUser = value; }
        }
        #endregion

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //this.initTodayTotal();
            //this.initYesterdayTotal();
        }

        private void initTodayTotal()
        {
            try
            {
                SpecialCmd scmd = new SpecialCmd();
                txttodayNormal.Content = scmd.GetNormal(DateTime.Now, DateTime.Now);
                txttodayLate.Content = scmd.GetLate(DateTime.Now, DateTime.Now);
                txttodayNo.Content = scmd.GetNo(DateTime.Now, DateTime.Now);
                txttodayfei.Content = scmd.GetFeiCount(DateTime.Now, DateTime.Now);
                string[] normalArr=txttodayNormal.Content.ToString().Split('/');

                txttodayPercent.Text = ((float.Parse(normalArr[0]) / float.Parse(normalArr[1])) * 100).ToString("0.00")+"%";
            }
            catch (Exception ex)
            {

                MessageBox.Show("统计今日打卡出错：" + ex.Message);
            }
        }

        private void initYesterdayTotal()
        {
            try
            {
                SpecialCmd scmd = new SpecialCmd();
                string[] normalArr = scmd.GetNormal(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1)).Split('/');
                float per = float.Parse(normalArr[0]) / float.Parse(normalArr[1]);
                txtYesPercent.Text = (per * 100).ToString("0.00")+"%";

                txtYesLate.Content = scmd.GetLate(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
                txtYesNo.Content = scmd.GetNo(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
                txtYesEndPercent.Text = scmd.GetEndPercent(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
                txtYesEndEarly.Content = scmd.GetEndEarly(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
                txtYesEndNo.Content = scmd.GetEndNo(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
                txtYesfei.Content = scmd.GetFeiCount(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
            }
            catch (Exception ex)
            {
                MessageBox.Show("统计昨日概况出错：" + ex.Message);
            }
        }


        

        #region Show dialog
        private void ShowSetDlg()
        {
            sys.Setings dlgsetings = new sys.Setings();
            dlgsetings.ShowDialog();
        }

        private void ShowLeaveRegDlg()
        {
            kaoQin.LeaveMgr dlgleavemgr = new kaoQin.LeaveMgr();
            dlgleavemgr.ShowDialog();
        }

        private void ShowGoOutRegDlg()
        {
            kaoQin.GoOutMgr goOutMgr = new kaoQin.GoOutMgr();
            goOutMgr.ShowDialog();
        }

        private void ShowOverTimeRegDlg()
        {
            kaoQin.OverTimeReg overtimeregDlg = new kaoQin.OverTimeReg();
            overtimeregDlg.ShowDialog();
        }
        #endregion

        #region Menu Events

        private void menuSetings_Click(object sender, RoutedEventArgs e)
        {
            this.ShowSetDlg();
        }
        /// <summary>
        /// 用户管理
        /// yd 2012-10-28
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuUserManager_Click(object sender, RoutedEventArgs e)
        {
            sys.User.SysUserMgr dlgSysuserMgr = new sys.User.SysUserMgr();
            dlgSysuserMgr.ShowDialog();
            
        }

        private void menuEmployee_Click(object sender, RoutedEventArgs e)
        {
            personnel.EmployeeMgr empMgr = new personnel.EmployeeMgr();
            empMgr.ShowDialog();
        }

        private void menuICCardMgr_Click(object sender, RoutedEventArgs e)
        {
            kaoQin.ICCardMgr icMgr = new kaoQin.ICCardMgr();
            icMgr.ShowDialog();
        }

        private void menuLeaveReg_Click(object sender, RoutedEventArgs e)
        {
            this.ShowLeaveRegDlg();
        }

        private void menuGoOutReg_Click(object sender, RoutedEventArgs e)
        {
            this.ShowGoOutRegDlg();
        }

        private void menuOverTimeReg_Click(object sender, RoutedEventArgs e)
        {
            this.ShowOverTimeRegDlg();
        }

        private void menuPQuery_Click(object sender, RoutedEventArgs e)
        {
            kaoQin.PQuery pquerydlg = new kaoQin.PQuery();
            pquerydlg.ShowDialog();
        }

        private void menuMofifyUserPwd_Click(object sender, RoutedEventArgs e)
        {
            sys.User.MofifyUserPwd pwddlg = new sys.User.MofifyUserPwd(_loginUser);
            pwddlg.ShowDialog();
        }

        private void menuKaoQinStatistics_Click(object sender, RoutedEventArgs e)
        {
            kaoQin.KaoQinStatistics statisdlg = new kaoQin.KaoQinStatistics();
            statisdlg.ShowDialog();
        }

        private void menuModifyUserBaseInfo_Click(object sender, RoutedEventArgs e)
        {
            sys.User.ModifyUserBaseInfo basedlg = new sys.User.ModifyUserBaseInfo(_loginUser);
            basedlg.ShowDialog();
        }
        #endregion

        #region tooBarEvents
        private void btnSysSet_Click(object sender, RoutedEventArgs e)
        {
            this.ShowSetDlg();
        }

        private void btnLeaveReg_Click(object sender, RoutedEventArgs e)
        {
            this.ShowLeaveRegDlg();
        }

        private void btnGout_Click(object sender, RoutedEventArgs e)
        {
            this.ShowGoOutRegDlg();
        }

        private void btnOverTime_Click(object sender, RoutedEventArgs e)
        {
            this.ShowOverTimeRegDlg();
        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("确定退出系统吗？", "确定", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.Yes)
            {
                this.Close();
            }
        }
        #endregion

        private void txttodayNormal_Click(object sender, RoutedEventArgs e)
        {
            ShowEmpKaoQinList(int.Parse(txttodayNormal.Content.ToString().Split('/')[0]),0, DateTime.Now, DateTime.Now);
        }

        private void txttodayLate_Click(object sender, RoutedEventArgs e)
        {
            ShowEmpKaoQinList(int.Parse(txttodayLate.Content.ToString()),1, DateTime.Now, DateTime.Now);
        }

        private void txttodayNo_Click(object sender, RoutedEventArgs e)
        {
            ShowNoList(int.Parse(txttodayNo.Content.ToString()), 0, DateTime.Now, DateTime.Now);
        }

        private void txttodayfei_Click(object sender, RoutedEventArgs e)
        {
            ShowFeiList(int.Parse(txttodayfei.Content.ToString()), DateTime.Now, DateTime.Now);
        }

        private void ShowEmpKaoQinList(int recordCount,int state, DateTime beginTime, DateTime endTime)
        {
            kaoQin.EmpKaoQinList emplsit = new kaoQin.EmpKaoQinList(recordCount,state, beginTime, endTime);
            emplsit.ShowDialog();
        }

        private void ShowNoList(int recordCount, int state, DateTime beginTime, DateTime endTime)
        {
            kaoQin.NoList nolist = new kaoQin.NoList(recordCount, state, beginTime, endTime);
            nolist.ShowDialog();
        }

        private void ShowFeiList(int recordCount, DateTime beginTime, DateTime endTime)
        {
            kaoQin.FeiList Feilist = new kaoQin.FeiList(recordCount, beginTime, endTime);
            Feilist.ShowDialog();
        }

        private void txtYesLate_Click(object sender, RoutedEventArgs e)
        {
            ShowEmpKaoQinList(int.Parse(txtYesLate.Content.ToString()), 1, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
        }

        private void txtYesNo_Click(object sender, RoutedEventArgs e)
        {
            ShowNoList(int.Parse(txtYesNo.Content.ToString()), 0, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
        }

        private void txtYesEndEarly_Click(object sender, RoutedEventArgs e)
        {
            ShowEmpKaoQinList(int.Parse(txtYesEndEarly.Content.ToString()), 3, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
        }

        private void txtYesEndNo_Click(object sender, RoutedEventArgs e)
        {
            ShowNoList(int.Parse(txtYesNo.Content.ToString()), 1, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
        }

        private void txtYesfei_Click(object sender, RoutedEventArgs e)
        {
            ShowFeiList(int.Parse(txtYesfei.Content.ToString()), DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
        }

        private void btnReDo_Click(object sender, RoutedEventArgs e)
        {
            initTodayTotal();
            initYesterdayTotal();
        }

        

        




    }
}
